// pages/Feedback/Feedback.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		tabs: [{
			id: 0,
			value: "商品反馈",
			isActive: true
		}, {
			id: 1,
			value: "投诉建议",
			isActive: false
		}],

		feedBackChoose: [{
			id: 0,
			value: '页面BUG',
			isActive: false
		}, {
			id: 1,
			value: '商品页面有误',
			isActive: false
		}, {
			id: 2,
			value: '投诉建议',
			isActive: false
		}, {
			id: 3,
			value: '商品质量问题',
			isActive: false
		}, {
			id: 4,
			value: '售后问题',
			isActive: false
		}, {
			id: 5,
			value: '实在是太TM贵了',
			isActive: false
		}, ],

		chooseImgArr: [],
		textVal: '',
		textValLength: 0,
		isActive: false
	},
	TabsItemsC(e) {
		const {
			index
		} = e.detail;
		let {
			tabs
		} = this.data;
		tabs.forEach((v, i) => {
			i === index ? v.isActive = true : v.isActive = false
		});
		this.setData({
			tabs
		})
	},
	FB_check(e){
		const {
			index
		} = e.currentTarget.dataset;
		console.log(index)
		let {
			feedBackChoose
		} = this.data;
		feedBackChoose.forEach((v, i) => {
			if(i === index){
				 v.isActive = !v.isActive
			}
			
		});
		this.setData({
			feedBackChoose
		})
	},
	
	
	uploadImgs() {
		wx.chooseImage({
			count: 9,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: (res) => {
				this.setData({
					chooseImgArr: [...this.data.chooseImgArr, ...res.tempFilePaths]
				})
			}
		})
	},
	removeIndex(e) {
		const {
			index
		} = e.detail;
		let {
			chooseImgArr
		} = this.data;
		chooseImgArr.splice(index, 1);
		this.setData({
			chooseImgArr
		})
	},

	textAreainp(e) {
		this.setData({
			textVal: e.detail.value,
			textValLength: e.detail.value.trim().length
		})
	},
	feedbackVal() {
		const {
			textVal,
			textValLength
		} = this.data;
		if (!textVal.trim() || textValLength < 10) {
			wx.showToast({
				title: '请至少输入10个字',
				icon: 'none',
				mask: true
			})
			return;
		} else {
			wx.showToast({
				title: '感谢反馈！',
				icon: 'success',
				mask: true,
				duration: 1500,
				success: function() {
					setTimeout((res) => {
						wx.navigateBack({
							delta: 1
						})
					}, 1500)
				}
			})
		}
	}
})
